<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                   http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.15.xsd">
    <changeSet id="init-table-TENNIS_USER_PROFILES-1" author="alisitsin">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="TENNIS_USER_PROFILES"/>
            </not>
        </preConditions>
        <createTable tableName="TENNIS_USER_PROFILES">
            <column name="TENNIS_USER_ID" type="integer" remarks="Идентификатор пользователя сервиса (первичный ключ)">
                <constraints primaryKey="true" primaryKeyName="PK_TENNIS_USER_PROFILES_ID"
                             foreignKeyName="FK_TENNIS_USER_TENNIS_USER_PROFILE" referencedTableName="TENNIS_USERS"
                             referencedColumnNames="TENNIS_USER_ID" nullable="false"/>
            </column>
            <column name="FIRST_NAME" type="varchar(255)" remarks="Имя пользователя"/>
            <column name="SURNAME" type="varchar(255)" remarks="Фамилия пользователя"/>
            <column name="PATRONYMIC" type="varchar(255)" remarks="Отчество пользователя (при наличии)"/>
            <column name="EXPERIENCE" type="integer" remarks="Опыт"/>
        </createTable>
        <comment>create table TENNIS_USER_PROFILES</comment>
    </changeSet>

    <changeSet id="add-column-BIRTHDAY-in-TENNIS_USER_PROFILES-1" author="alisitsin">
        <preConditions onFail="MARK_RAN">
            <and>
                <tableExists tableName="TENNIS_USER_PROFILES"/>
                <not>
                    <columnExists tableName="tennis_user_profiles" columnName="birthday"/>
                </not>
            </and>
        </preConditions>
        <addColumn tableName="tennis_user_profiles">
            <column name="birthday" type="date" remarks="Дата рождения"/>
        </addColumn>
        <comment>add column BIRTHDAY in TENNIS_USER_PROFILES</comment>
    </changeSet>

    <changeSet id="add-column-USER_RATING-in-TENNIS_USER_PROFILES-1" author="alisitsin">
        <preConditions onFail="MARK_RAN">
            <and>
                <tableExists tableName="TENNIS_USER_PROFILES"/>
                <not>
                    <columnExists tableName="tennis_user_profiles" columnName="user_rating"/>
                </not>
            </and>
        </preConditions>
        <addColumn tableName="tennis_user_profiles">
            <column name="user_rating" type="integer" remarks="Рейтинг пользователя"/>
        </addColumn>
        <comment>add column user_rating in TENNIS_USER_PROFILES</comment>
    </changeSet>

</databaseChangeLog>